<?php
/**
 * Created by PhpStorm.
 * User: lenovo
 * Date: 2018/9/29
 * Time: 14:59
 */
include "config.php";
session_start();
$response=array();
if($_SERVER["REQUEST_METHOD"]=="POST"){
    $uname=$_POST["uname"];
    $upwd=$_POST["upwd"];
    $sql="SELECT *FROM userinfo WHERE u_name=? AND u_pwd=?";
    $res=$link->prepare($sql);
    //绑定数据
    $res->bind_param("ss",$uname,$upwd);
    //执行sql语句
    $res->execute();
 $result=$res->get_result();
 if($result->num_rows>=1){
    $_SESSION["user"]=$result->fetch_assoc();
     $response["state"]=1;
     $response["msg"]="登录成功";
     $response["s"]=$_SESSION["user"];
     print_r(json_encode($response));
 }else{
     $response["state"]=0;
     $response["msg"]="登录失败";
     print_r(json_encode($response));
 }
    $link->close();
}else{
    $response["state"]=-1;
    $response["msg"]="请使用post请求";
    print_r(json_encode($response));
}